<#include "/java_copyright.include">
<#assign className = table.className>   
<#assign tableName = table.sqlName>   
<#assign classNameLower = className?uncap_first>
package ${basepackage}.action;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

<#include "/java_imports.include">

public class ${className}Action {
	private ${className}Service ${classNameLower}Service = new ${className}Service();
	
	public String save(Context c){
		Connection conn = ConnectionPool.getConnection();
		try{
			conn.setAutoCommit(false);
			${className} ${classNameLower} = new ${className}();
			<#list table.pkColumns as column>
			${classNameLower}.set${column.columnName}(c.get${column.simpleJavaType}("${column.javaName}"));
			</#list>
			${classNameLower}Service.insert(conn,${classNameLower});
			return "saveSuccess";
		} catch(Exception e){
			c.getRequest().setAttribute("err",e);
			return "error";
		}finally{
			CommUtil.close(conn);
		}
	}

	public boolean modify(Connection conn,${className} ${classNameLower}){
		Connection conn = ConnectionPool.getConnection();
		try{
			conn.setAutoCommit(false);
			${className} ${classNameLower} = new ${className}();
			<#list table.pkColumns as column>
			${classNameLower}.set${column.columnName}(c.get${column.simpleJavaType}("${column.javaName}"));
			</#list>
			${classNameLower}Service.update(conn,${classNameLower});
			return "modifySuccess";
		} catch(Exception e){
			c.getRequest().setAttribute("err",e);
			return "error";
		}finally{
			CommUtil.close(conn);
		}
	}

	public boolean remove(Connection conn,${className} ${classNameLower}){
		Connection conn = ConnectionPool.getConnection();
		try{
			conn.setAutoCommit(false);
			Integer id = c.getInteger("id");
			${classNameLower}Service.delete(conn,id);
			return "removeSuccess";
		} catch(Exception e){
			c.getRequest().setAttribute("err",e);
			return "error";
		}finally{
			CommUtil.close(conn);
		}
	}
	
	public ${className} show(Connection conn,Integer id){
		Connection conn = ConnectionPool.getConnection();
		try{
			Integer id = c.getInteger("id");
			${classNameLower}Service.get(conn,id);
			return "show";
		} catch(Exception e){
			c.getRequest().setAttribute("err",e);
			return "error";
		}finally{
			CommUtil.close(conn);
		}
	}
	
	public List<${className}> list(Connection conn){
		Connection conn = ConnectionPool.getConnection();
		try{
			${classNameLower}Service.list(conn);
			return "list";
		} catch(Exception e){
			c.getRequest().setAttribute("err",e);
			return "error";
		}finally{
			CommUtil.close(conn);
		}
	}
	
}
